package com.itheima.app.controller;

import com.itheima.app.manager.UserLikeManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserLikeController {

    @Autowired
    private UserLikeManager userLikeManager;

    // 探花-喜欢
    @GetMapping("/tanhua/{likeUserId}/love")
    public ResponseEntity tanhuaLove(@PathVariable Long likeUserId) {
        // 调用manager
        userLikeManager.tanhuaLove(likeUserId);
        return ResponseEntity.ok(null);
    }

    // 探花-不喜欢
    @GetMapping("/tanhua/{likeUserId}/unlove")
    public ResponseEntity tanhuaUnLove(@PathVariable Long likeUserId) {
        // 调用manager
        userLikeManager.tanhuaUnLove(likeUserId);
        return ResponseEntity.ok(null);
    }

    // 用户喜欢相关信息统计查询
    @GetMapping("/users/counts")
    public ResponseEntity userCount() {
        // 调用manager
        return userLikeManager.userCount();
    }

    // 喜欢、粉丝、历史访客详情
    @GetMapping("/users/friends/{type}")
    private ResponseEntity findUserDetailByPage(
            @PathVariable Integer type,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "8") Integer pageSize) {

        // 调用manager
        return userLikeManager.findUserDetailByPage(type, pageNum, pageSize);
    }

    // 粉丝详情页-喜欢
    @PostMapping("/users/fans/{likeUserId}")
    public ResponseEntity usersFansLove(@PathVariable Long likeUserId) {
        // 调用manager
        userLikeManager.tanhuaLove(likeUserId);

        return ResponseEntity.ok(null);
    }

    // 相互喜欢、喜欢详情页-取消喜欢
    @DeleteMapping("/users/like/{likeUserId}")
    public ResponseEntity usersUnLove(@PathVariable Long likeUserId){
        // 调用manager
        userLikeManager.tanhuaUnLove(likeUserId);
        return ResponseEntity.ok(null);
    }
}
